/**
 * package: seeds
 * author: zhaiyujin
 * description:
 */
package seeds

import (
	"fmt"
	"github.com/casbin/casbin/v2"
	"gorm.io/gorm"
	"huanteng/web/models"
	"huanteng/web/repositories"
)

func SeedCasbin(db *gorm.DB,enforcer *casbin.Enforcer)  {
	var roles []models.Role
	err:=db.Find(&roles).Error
	if err!=nil{
		panic(err)
	}
	if len(roles)==0{
		fmt.Println("一个都没有")
		return
	}

	//为用户添加角色
	_=repositories.CsbinAddRoleForUser(1)
	//为角色添加权限
	repositories.CsbinSetRolePermission(2)
	//设置角色菜单
	for _,role:=range roles{
		repositories.SetRolePermission(enforcer,role.ID)
	}



}
